/**
 * Project: lionbule-other
 * 
 * File Created at 2012-4-5
 * $Id$
 * 
 * Copyright 1999-2100 Alibaba.com Corporation Limited.
 * All rights reserved.
 *
 * This software is the confidential and proprietary information of
 * Alibaba Company. ("Confidential Information").  You shall not
 * disclose such Confidential Information and shall use it only in
 * accordance with the terms of the license agreement you entered into
 * with Alibaba.com.
 */
package com.verfy.parser;

import java.util.Collections;
import java.util.List;

/**
 * OptionExpression.
 * 
 * @author LionBule 2012-4-5 下午6:38:33
 */
public class OptionExpression implements Expression {
    public static final int     IN       = 1;
    public static final int     NOT_IN   = 2;

    private List<String> dataList = Collections.emptyList();
    private int          flag;

    public OptionExpression(int flag, List<String> dataList) {
        this.flag = flag;
        this.dataList = dataList;
    }

    @Override
    public boolean matche(Object data) {
        if (data == null) {
            return true;
        }

        String argValue = data.toString();
        switch (flag) {
            case IN: {
                return dataList.contains(argValue);
            }
            case NOT_IN: {
                return !dataList.contains(argValue);
            }
            default: {
                throw new ExpressionException("no support this expression. flag=" + flag);
            }
        }

    }
}
